Skip to content

Add item sources and per-site vote locking - #6

Open
mgilardi wants to merge 2 commits into
mainfrom
co/item-sources
Open

mgilardi wants to merge 2 commits into
mainfrom
co/item-sources

Conversation

@mgilardi

Copy link
Copy Markdown
Collaborator

Captive Origins task: K5038. Follows: D5008 (owner, 2026-11-16).

Adds itemSources with syncItemSources and syncItemSource, and votes.lock (default true). Source items are ordinary items, never deleted (marked sourceGone), take no Roadmap votes, and their source fields are not writable through the API. 55 tests pass; no version bump.

Not tested: tags (ignored), scopeField sites, large sources, concurrent syncs, Postgres and SQLite.

🤖 Generated with Claude Code

Lets another plugin offer items to a board (language requests, for one) with no import either way, and lets a site turn off placed-vote locking.

Sync marks vanished items instead of deleting them. Not tested: tags, scopeField sites, very large sources, concurrent syncs, Postgres and SQLite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mgilardi

Copy link
Copy Markdown
Collaborator Author

Security and privacy review (EXTANT APE, Head of Research for Simon)

Verdict: changes. Ordinary voters can't abuse votes, and the lock runs on the server. Three things should be fixed before merge: votes can still reach a source item, one bad slug stops the whole sync, and the lock's refusal has no test.

Checked and fine

  • CI green. Local: 55 of 55 tests pass.
  • The owner's ruling holds: with votes.lock: false, lockDays is ignored (unlocksAt returns null at src/api.ts:224, and beforeDelete uses the same function).
  • Source fields (sourceKey, externalId, sourceVotes, sourceGone, voteCount) can't be written through the API, staff included. Items stay manager-only.
  • A voter can't vote twice (unique item+user+ballot), can't vote as someone else, and can't set a weight or ballot. Voter identities aren't newly exposed.

Fix before merge

  1. Votes can be moved onto a source item. The refusal in the votes beforeChange hook only runs on create (src/collections.ts, operation !== 'create'). A curator merging an ordinary item into a source item (mergeItems), or editing a vote's item, moves votes onto it. recountVotes then writes the Roadmap tally into voteCount, and the next sync overwrites it with the source count. Voters' placed votes end up spent where they don't count. Suggested fix: refuse source items as a vote's item on update too, and leave them out of the merge target's filterOptions and its check.
  2. One collision aborts the sync. Items are unique on (scope, board, key), and a source item's key comes from slugFor(key, externalId). A public requestItem whose title slugifies to the same text claims that key first. The same happens on its own when ids such as lang:zu and lang-zu map to one slug, when the 120-character cut makes two ids equal, or when a source item has an empty title. The create in syncOne isn't caught, so every item after it is skipped and gone-marking never runs (src/sources.ts:45-50). Suggested fix: give source items a key namespace requests can't produce (for example source:<key>:<externalId> instead of a slug), and catch per-item failures so one bad item is reported and the rest still sync.
  3. The server-side lock is untested (test/sources.test.ts:138-147). Both lock tests use withdrawVotes, which runs with overrideAccess. No test sends a voter's own delete through the API, so the beforeDelete refusal (403, "These votes are still committed.") is never exercised. It's a fail-closed check, so it needs a test with the lock on and with it off.

Worth doing (not blocking)
4. Refusal tests use a bare rejects.toThrow(). Match the message or status, and add a curator voting on a source item and a vote moved onto one.
5. votes.lock isn't checked to be a boolean ('false' keeps votes locked). allocation.lockDays has no range check, so NaN or a negative number unlocks votes straight away. This is older code, but it decides the lock. Validate both when the options are read.
6. Multi-site: source items are created with no scopeField value (src/sources.ts:47), and item read access has no scope filter. Whether they show on every site or on none depends on the host's tenant plugin. The README says each site has its own roadmap. Either set the scope from the source config or document it. The CHANGELOG already marks this untested.
7. The docs call votes.lock per site, but it's one setting per Payload config. Say so.
8. castVote and allocateVotes refuse source items through the hook's APIError rather than a RoadmapError, so hosts that show only RoadmapError messages give voters a generic error.

🤖 Generated with Claude Code

…ad items

Votes could be moved onto a source item by a merge or an edit, and a request
slug could collide with a source key and stop the whole sync. Source items now
refuse merges and moved votes, use a source:<key>:<id> key, and a failing item
is skipped and reported. Adds server-side lock tests, option validation and a
scope option.

Not tested: a tenant plugin with scope; Postgres and SQLite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant